class CSequence
{
	public enum enum_SetOfCards
	{
		SOC_NULL(0), SOC_HIGH_CARD(1), SOC_HIGH_CARD_NEAR_STRAIGHT(1), SOC_HIGH_CARD_NEAR_STRAIGHT_FLUSH(1), SOC_ONE_PAIR(2), SOC_TWO_PAIR(3),
		SOC_THREE_OF_A_KIND(4), SOC_STRAIGHT(5), SOC_FLUSH(6), SOC_FULL_HOUSE(7), SOC_FOUR_OF_A_CARD(8), SOC_STRAIGHT_FLUSH(9); 
		
		private int int_ValueOfSet;
		private enum_SetOfCards(int int_ValueOfSet)
		{
			this.int_ValueOfSet = int_ValueOfSet;
		}
	 	
		public int getValue()
	 	{
	 		return	int_ValueOfSet;
	 	}
	}
	
	public enum_SetOfCards soc_SetOfCards;
	public CCard[] cards_SetOfCards = new CCard[5];

	public CSequence()
	{
		for(int i=0;i<5;++i){cards_SetOfCards[i]= new CCard();}
		soc_SetOfCards = enum_SetOfCards.SOC_NULL;
	}
	
	public CSequence(CCard[] cards_In)
	{	
		CQuick.quicksort(cards_In, 0, 4);
		
		for(int i=0;i<5;++i)
		{
			cards_SetOfCards[i]=new CCard();
			cards_SetOfCards[i]=cards_In[i];
		}
		soc_SetOfCards = enum_SetOfCards.SOC_NULL;
	}
	
	private CSequence CreateSequenceSupport(CCard[] card_Input)
	{
		int int_Pointer = 0;
		int int_Index = 0;
		
		CSequence seg_Support = new CSequence();
		
		for(int i=4;i>=1;--i)
		{	
			for(int j=0;j<4;++j)
			{
				if(card_Input[j].getIntegerValueOfCard()!=card_Input[j+1].getIntegerValueOfCard() || j==3)
				{	
					if(card_Input[j].getIntegerValueOfCard()==card_Input[j+1].getIntegerValueOfCard()){++j;}
					
					if(j-int_Pointer+1==i)
					{
						if(i==4){seg_Support.soc_SetOfCards = enum_SetOfCards.SOC_FOUR_OF_A_CARD;}
						else if(i==3){seg_Support.soc_SetOfCards = enum_SetOfCards.SOC_THREE_OF_A_KIND;}
						else if(i==2 && seg_Support.soc_SetOfCards == enum_SetOfCards.SOC_THREE_OF_A_KIND)
						{seg_Support.soc_SetOfCards = enum_SetOfCards.SOC_FULL_HOUSE;}
						else if(i==2 && seg_Support.soc_SetOfCards == enum_SetOfCards.SOC_ONE_PAIR)
						{seg_Support.soc_SetOfCards = enum_SetOfCards.SOC_TWO_PAIR;}
						else if(i==2){seg_Support.soc_SetOfCards = enum_SetOfCards.SOC_ONE_PAIR;}
						for(int k=0;k<i;++k)
						{
							seg_Support.cards_SetOfCards[int_Index]= card_Input[int_Pointer+k];
							//System.out.println(seg_Support.deck_SetOfCards.card_ArrayOfHandDeck[int_Index].getValueOfCardName());
							++int_Index;
						}
					}
					int_Pointer = j+1;
				}
			}
			int_Pointer = 0;
		}
		//System.out.println(seg_Support.cards_SetOfCards[0].getValueOfCardName());
		return seg_Support;
	}
	
	public CSequence  getSequenceOfCards()
	{
		CSequence seg_Result = new CSequence();
		seg_Result.cards_SetOfCards = cards_SetOfCards;
		seg_Result.soc_SetOfCards = enum_SetOfCards.SOC_HIGH_CARD;
		boolean bool_IdenticalColor = true;

			for(int i=4;i>0;--i)
			{
				if(cards_SetOfCards[i].getIntegerValueOfCard() == (cards_SetOfCards[i-1].getIntegerValueOfCard()-1))
				{
					if(cards_SetOfCards[i].getColorOfCard()!=cards_SetOfCards[i-1].getColorOfCard()){bool_IdenticalColor = false;}
				}
				else{break;}
				
				if(i==1 && bool_IdenticalColor)
				{
					seg_Result.soc_SetOfCards=enum_SetOfCards.SOC_STRAIGHT_FLUSH;
				}
				else if(i==1)
				{
					seg_Result.soc_SetOfCards=enum_SetOfCards.SOC_STRAIGHT;
				}
				else if(i<3 && bool_IdenticalColor){seg_Result.soc_SetOfCards=enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT_FLUSH;}
				else if(i<3){seg_Result.soc_SetOfCards=enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT;}
			}
			if(seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_HIGH_CARD){seg_Result = CreateSequenceSupport(cards_SetOfCards);}
			
			if((seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_NULL || seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT || seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT_FLUSH ||seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_HIGH_CARD) && bool_IdenticalColor)
			{
				seg_Result.soc_SetOfCards = enum_SetOfCards.SOC_FLUSH;
				seg_Result.cards_SetOfCards = cards_SetOfCards;
			}
			else if(seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_NULL)
			{
				seg_Result.soc_SetOfCards = enum_SetOfCards.SOC_HIGH_CARD;
				seg_Result.cards_SetOfCards = cards_SetOfCards;
			}
			if(seg_Result.soc_SetOfCards == enum_SetOfCards.SOC_ONE_PAIR){seg_Result.cards_SetOfCards[4]=cards_SetOfCards[4];}
		//System.out.println(seg_Result.cards_SetOfCards[0].getIntegerValueOfCard());
		return seg_Result;
	}
	
 	static int ComparisonSequence(CSequence seg_First, CSequence seg_Secound)
	{
 		if(seg_First.soc_SetOfCards.int_ValueOfSet>seg_Secound.soc_SetOfCards.int_ValueOfSet) return 1;
 		else if(seg_First.soc_SetOfCards.int_ValueOfSet<seg_Secound.soc_SetOfCards.int_ValueOfSet) return 2;
 		else if(seg_First.soc_SetOfCards.int_ValueOfSet==seg_Secound.soc_SetOfCards.int_ValueOfSet)
 		{
 			for(int i=0;i<5;++i)
 			{
 				if(seg_First.cards_SetOfCards[i].getIntegerValueOfCard() > seg_Secound.cards_SetOfCards[i].getIntegerValueOfCard()){return 1;}
 				if(seg_First.cards_SetOfCards[i].getIntegerValueOfCard() < seg_Secound.cards_SetOfCards[i].getIntegerValueOfCard()){return 2;}
 			}
 		}
		return 0;
	}

}